package com.mvc4g.example.shareModel.client.view.views;

import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.mvc4g.example.shareModel.client.bean.BeanC;
import com.mvc4g.example.shareModel.client.util.HasModelLoadHandler;
import com.mvc4g.example.shareModel.client.util.ModelLoadEvent;
import com.mvc4g.example.shareModel.client.util.ModelLoadHandler;

public class ViewC extends AbstractView implements HasModelLoadHandler<BeanC> {
	
	HandlerManager handlerManager = new HandlerManager(this);

	private Label label = null;
	
	private BeanC modelC = null;

	@Override
	protected Widget createWidget() {
		label = new Label();
		return label;
	}
	
	public void setModelC(BeanC modelC){
		this.modelC = modelC;
		ModelLoadEvent<BeanC> e = new ModelLoadEvent<BeanC>(modelC);
		handlerManager.fireEvent(e);
	}
	
	public BeanC getModel(){
		return modelC;
	}
	
	public void init(){
		label.setText("Information of C: " + modelC.getInfo());
	}
	
	public void restart(){
		modelC = null;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public HandlerRegistration addModelLoadHandler(ModelLoadHandler handler) {
		return handlerManager.addHandler(ModelLoadEvent.TYPE, handler);
	}

}
